// See LICENSE.TXT for terms of use, and copyright information

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/power.h>
#include "common.h"
#include "sleep.h"

void idle() {
	MCUCR = 1<<PUD | 1<<SE | 0<<SM1 | 0<<SM0 | 0<<ISC01 | 0<<ISC00; // idle mode
	asm("sleep"); // go to sleep to save power; wait for timer interrupt
}

void deepsleep() {
	// deepest sleep mode
	cli(); // disable interrupts
	VALR = 0x00;
	VALG = 0x00;
	VALB = 0x00;
	VALI = 0x00;

	// XXX Doesn't look like the 2313 has as advanced power modes.
	//PRR = 1<<PRTIM0 | 1<<PRADC; // power down timer/counter0 & ADC
	//MCUCR = 1<<BODS | 1<<BODSE; // enable BOD disable during sleep, step 1
	//MCUCR = 1<<BODS | 0<<BODSE; // step 2

	MCUCR = 1<<PUD | 1<<SE | 1<<SM1 | 0<<SM0 | 0<<ISC01 | 0<<ISC00; // select "power down" mode
	asm("sleep"); // go to sleep to save power

}
